﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Collections;


namespace iLangl.Model
{
	public class ProjectTPResponseContext : ProjectResponseContext
	{
		public override void SetContext(object context)
		{
			base.SetContext(context); 

			XmlNodeList companynodes = document.SelectNodes("//Company");

			CompanyResponseContext companyResponseContext = new CompanyResponseContext();

			Hashtable companies = new Hashtable();

			foreach (XmlNode nodecompany in companynodes)
			{
				companyResponseContext.SetContext(nodecompany);
				Company company = (Company)companyResponseContext.GetContext();

				foreach (Contact contact in company.Contacts)
				{
					contact.Company = company;
				}

				companies[company.Id] = company;
			}

			if ((_project.Owner != null) && (_project.Owner.Company != null))
			{
				Company company = (Company )companies[_project.Owner.Company.Id];

				if (company != null)
					_project.Owner.Company = company;
			}

			if ((_project.TechnicalContact != null) && (_project.TechnicalContact.Company != null))
			{
				Company company = (Company)companies[_project.TechnicalContact.Company.Id];

				if(company != null)
					_project.TechnicalContact.Company = company;
			}


			foreach (Translation trans in _project.Translations)
			{


				if ((trans.Responsible != null) && (trans.Responsible.Company != null))
				{
					Company company = (Company)companies[trans.Responsible.Company.Id];

					if(company != null)
						trans.Responsible.Company = company;
				}
			}
			
		}
	}
}
